home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 9
/
Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO
/
038a
/
satsfaxt.zip
/
CCPUTILS.EXE
/
CCSEND.C
< prev
next >
Wrap
Text File
|
1990-01-30
|
34KB
|
733 lines
/*---------------------------------------------------------------------------*
* CCSEND.C *
*---------------------------------------------------------------------------*
* The program manages the CC hardware as specified in the DCA/Intel *
* CAS spec. All options, filenames and addresses are specified *
* on the command line. *
* *
* The following source code is intended to assist developers in *
* creating applications which support the DCA/Intel Communicating *
* Applications Specification Version 1.0A. It is provided free of charge *
* and on an as-is basis. THE IMPLIED WARRENTIES OF MERCHANTABILITY AND *
* FITNESS FOR A PARTICULAR PURPOSE ARE SPECIFICALLY EXCLUDED. This source *
* code may be modified, enhanced, copied and distributed with applications *
* that support CAS on a royalty free basis. *
*===========================================================================*/
#include <stdio.h>
#include <dos.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <string.h>
#include <malloc.h>
#include <time.h>
#include <io.h>
#include "cas.h" /* Intel CAS header file. */
#include "parse.h" /* Command line parser header file. */
#include "util.h" /* CAS utilities header file. */
#define TEMPLATE "CCXXXXXX" /* Template for tempory filename. */
/* Data structures for interfacing with CAS library. */
SFTR *SFTRbuffer; /* Single File Transfer buffer. */
FTR *FTRbuffer[10]; /* File Transfer buffer. */
ECF *TCFbuffer; /* Task Control File buffer. */
EDB *EDBbuffer; /* External Data Block buffer. */
FILE *ccout; /* Redirected stdout file. */
/* Command line variables. */
FileMode = FALSE; /* Transfer mode (file or FAX). */
char *SendDate; /* Date to send. */
char *SendTime; /* Time to send. */
char *Cover; /* Cover page text. */
char *CoverFile; /* Get cover text from file. */
char *Phone; /* Phone number to dial. */
char *Logo; /* Logo file path. */
int DefLogo = FALSE; /* Use default logo file (EDB). */
int WideFont = FALSE; /* 132 column font. */
int HiRes = FALSE; /* High resolution (200x200 dpi) */
int Help = FALSE; /* Show help message. */
int RedirOut = FALSE; /* Redirect output to file. */
/* Days per month - used for date checking. */
int DaysPerMonth[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
/* Argument table for command line processor. */
STABLE SwitchTable[] =
{
{ 'M', STRING, (int *)&Cover },
{ 'm', STRING, (int *)&Cover },
{ 'C', STRING, (int *)&CoverFile },
{ 'c', STRING, (int *)&CoverFile },
{ 'D', STRING, (int *)&SendDate },
{ 'd', STRING, (int *)&SendDate },
{ 'T', STRING, (int *)&SendTime },
{ 't', STRING, (int *)&SendTime },
{ 'X', BOOL, &FileMode },
{ 'x', BOOL, &FileMode },
{ 'L', STRING, (int *)&Logo },
{ 'l', STRING, (int *)&Logo },
{ 'P', STRING, (int *)&Phone },
{ 'p', STRING, (int *)&Phone },
{ 'W', BOOL, (int *)&WideFont },
{ 'w', BOOL, (int *)&WideFont },
{ 'H', BOOL, (int *)&HiRes },
{ 'h', BOOL, (int *)&HiRes },
{ 'R', BOOL, &RedirOut },
{ 'r', BOOL, &RedirOut },
{ '?', BOOL, &Help }
};
#define TABLESIZE (sizeof(SwitchTable)/sizeof(STABLE))
char *DescTable[] = /* Help function description table. */
{
"CCSEND (V1.0) Sends the file or fax specified by \"filename\". \"filename\" may\n",
"include a path (for example, c:\\aim\\guides.doc).\n\n",
"/P<number> is the phone number to send to. Use a comma for delay (for\n",
"example, /p9,555-1212). Characters such as \"-\" and \"( )\" are ignored.\n",
"The default is no cover page. A cover page will be sent if you specify /L,\n",
"/M, or /C.\n\n",
"Syntax: CCSEND filename... /P<number> [option...]\n\n"
};
#define DESCSIZE (sizeof(DescTable)/sizeof(DescTable[0]))
char *HelpTable[] =
{
" /L<filename> Logo file to send. \"default\" sends default logo.\n",
" /M<text> Cover page message, in quotes.\n",
" /C<filename> Get cover page message from file.\n",
" /D<mm/dd/yy> Date to send.\n",
" /T<hh:mm> Time to send.\n\n",
" /X Use file transfer (default is FAX).\n",
" /W Use wide (132 col) font (Only valid for FAX's).\n",
" /H Use high resolution fax (200x200 dpi).\n\n",
" /R Redirect output to file OUTPUT.CC.\n",
" /? Display help information.\n",
};
#define HELPSIZE (sizeof(HelpTable)/sizeof(HelpTable[0]))
/*---------------------------------------------------------------------------*
* GetTime() *
*---------------------------------------------------------------------------*
* Function to convert ASCII time (hh:mm:ss) to DOS time format (packed *
* word). Minimal error checking is performed for reasonable values for *
* the hour, minute and second. *
*---------------------------------------------------------------------------*
* Parameters: char *gTime - CAS time structure. *
* Return: Time in packed word format. *
*---------------------------------------------------------------------------*/
unsigned GetTime(char *cTime)
{
int hour, minute, second; /* Place to store normal time values. */
unsigned w_time = 0; /* Time packed into a single word. */
char buffer[10]; /* Holds to string version of the time. */
if(cTime == NULL)
_strtime(buffer);
else
strcpy(buffer, cTime);
hour = atoi(strtok(buffer, ":"));
minute = atoi(strtok(NULL, ":"));
second = atoi(strtok(NULL, ":")) / 2;
/* Check for invalid time specification. */
if((hour < 0 || hour > 23) || (minute < 0 || minute > 59) || (second < 0 || second > 59))
CASError(CASBADTIME, TRUE, 0);
/* Squeeze the time into a single word. */
w_time = second | (minute << 5) | (hour << 11);
return(w_time);
}
/*---------------------------------------------------------------------------*
* GetDate *
*---------------------------------------------------------------------------*
* Convert ASCII date (dd/mm/yy) to DOS date format (packed word). Minimal *
* error checking is performed to check for reasonable values for day, *
* month and year. *
*---------------------------------------------------------------------------*
* Paramters: char *date - CAS date structure. *
* Return: Date in packed word format. *
*---------------------------------------------------------------------------*/
unsigned GetDate(char *cDate)
{
int month, day, year; /* Place to hold the normal date values. */
unsigned w_date = 0; /* Date packed into single word. */
char buffer[10]; /* Holds string version of date. */
if(cDate == NULL)
_strdate(buffer);
else
strcpy(buffer, cDate);
month = atoi(strtok(buffer, "/"));
day = atoi(strtok(NULL, "/"));
year = atoi(strtok(NULL, "/")) - 80;
/* Check for invalid dates. */
if(month < 1 || month >12)
CASError(CASBADDATE, TRUE, 0);
if((((year + 1980) % 4) == 0) && (month == 2)) {
/* Leap year checking. */
if(day < 1 || day > 29)
CASError(CASBADDATE, TRUE, 0);
}
else {
/* Normal year checking. */
if(day < 1 || day > DaysPerMonth[month])
CASError(CASBADDATE, TRUE, 0);
}
if(year < 0 || year > 19)
CASError(CASBADDATE, TRUE, 0);
/* Sqeeze the date into a single word. */
w_date = day | (month << 5) | (year << 9);
return(w_date);
}
/*---------------------------------------------------------------------------*
* SendSingle() *
*---------------------------------------------------------------------------*
* Send a single file. This function is called when the command line contains*
* only one file to send. Most options can be changed from the command line. *
*---------------------------------------------------------------------------*
* Parameters: char *filename - Name of file to send. *
* SFTR *SFTRbuffer - Filled in SFTR structure. *
* Return: Event handle. *
*---------------------------------------------------------------------------*/
SendSingle(char *filename, SFTR *SFTRbuffer)
{
int CharsUsed = 0; /* Number of chars in cover text. */
int EventHandle; /* Event handle returned from CAS. */
int i; /* Loop Counter. */
int spaceleft; /* Keeps track of space used in cover. */
FILE *fh; /* DOS file handle of cover file. */
char c[2]; /* Char to read cover file into. */
struct stat fbuffer; /* DOS stat structure. */
c[1] = '\0';
/* Lets set the entire buffer to a known state. */
strnset((char *)SFTRbuffer, '\0', sizeof(SFTR));
if(FileMode) /* TransferType 0 */
SFTRbuffer->TransferType = FILE_TRANSFER;
else if (HiRes)
SFTRbuffer->TransferType = FAX_200;
else
SFTRbuffer->TransferType = FAX_100;
if(!FileMode && WideFont)
SFTRbuffer->TextSize = 1; /* TextSize 132 col 1 */
else
SFTRbuffer->TextSize = 0; /* 80 col */
SFTRbuffer->EventTime = GetTime(SendTime); /* EventTime 2 */
SFTRbuffer->EventDate = GetDate(SendDate); /* EventDate 4 */
strncpy(SFTRbuffer->DestinationName, Phone, 31);/* DestinationName 6 */
strncpy(SFTRbuffer->FileName, filename, 79); /* FileName 38 */
strncpy(SFTRbuffer->Phone, Phone,46); /* Phone 118 */
strncpy(SFTRbuffer->ApplicationTag, "CCSEND", 63); /* ApplicationTag 165 */
SFTRbuffer->RESERVED1 = 0; /* RESERVED1 229 */
if((Cover == NULL) && (CoverFile == NULL)) /* SendCover 230 */
SFTRbuffer->SendCover = NO_COVER;
else
SFTRbuffer->SendCover = COVER;
strnset(SFTRbuffer->RESERVED2, '\0', 23); /* RESERVED2 231 */
/* Copy the cover page text (first from the command line, then from the
specified cover page file 254 */
if(strlen(Cover) != 0) {
CharsUsed = strlen(Cover) + 2;
strcpy(&SFTRbuffer->CoverTextDummy, Cover);
strcat(&SFTRbuffer->CoverTextDummy, "\n\n");
if(strlen(CoverFile) == 0)
strcat(&SFTRbuffer->CoverTextDummy, "\0");
}
else
CharsUsed = 0;
if(strlen(CoverFile) != 0) {
/* If cover file was specified, read it into SFTR after the command
line specified cover text. */
if(!IsASCIIFile(CoverFile))
CASError(CASBADCOVERFILE, TRUE, 0);
if((fh = fopen(CoverFile, "r")) == NULL)
CASError(CASOPENTEMP, TRUE, 0);
else {
fstat(fileno(fh), &fbuffer);
if(strlen(Cover) == 0)
strcpy(&SFTRbuffer->CoverTextDummy, "");
for(i = ++CharsUsed; (i < 2880) && (i < fbuffer.st_size); i++) {
fread(&c[0], 1, 1, fh);
strcat(&SFTRbuffer->CoverTextDummy, c);
}
strcat(&SFTRbuffer->CoverTextDummy, "\0"); /* ASCIIZ terminator */
fclose(fh);
}
}
if((EventHandle = CASSubmitSingleFile(SFTRbuffer)) > 0)
return(EventHandle);
else
CASError(CASSEND, TRUE, -EventHandle);
}
/*---------------------------------------------------------------------------*
* FillTCF() *
*---------------------------------------------------------------------------*
* Fills in an ECF structure in preperation to save it as a Task Control *
* file. *
*---------------------------------------------------------------------------*
* Parameters: ECF *TCFbuffer - Uninitialized ECF structure. *
* int file_count - Number of files to send. *
* Return: int value indicating the maximum cover file size. *
*---------------------------------------------------------------------------*/
int FillTCF(ECF *TCFbuffer, int file_count)
{
int textsize; /* Size of cover text on command line. */
int filesize; /* Sixe of cover file. */
struct stat fbuffer; /* DOS stat buffer. */
/* Lets set the entire buffer to a known state. */
strnset((char *)TCFbuffer, '\0', sizeof(ECF));
TCFbuffer->EventType = SEND; /* EventType 0 */
if(FileMode) /* TransferType 1 */
TCFbuffer->TransferType = FILE_TRANSFER;
else if (HiRes)
TCFbuffer->TransferType = FAX_200;
else
TCFbuffer->TransferType = FAX_100;
TCFbuffer->EventStatus = 0; /* EventStatus 2 */
TCFbuffer->EventTime = GetTime(SendTime); /* EventTime 4 */
TCFbuffer->EventDate = GetDate(SendDate); /* EventDate 6 */
TCFbuffer->FileCount = file_count; /* FileCount 8 */
/* Have to get the size of the cover text (/m) if any. Add 4 to account
for two newlines that will be appended to the cover text. */
if(Cover) {
textsize = strlen(Cover) + 2;
}
else
textsize = 0;
/* Have to get the size of the cover file if any. */
if(CoverFile) {
stat(CoverFile, &fbuffer);
if(fbuffer.st_size + textsize > 2880)
filesize = 2880 - textsize;
else
filesize = fbuffer.st_size;
}
else
filesize = 0;
TCFbuffer->FTROffset = 383 + textsize + filesize;
if(Cover || CoverFile)
/* Have to account for the null character that will be appended by
adding 1 to the total length. */ /* FTROffset 10 */
TCFbuffer->FTROffset++;
strncpy(TCFbuffer->Phone, Phone, 46); /* Phone 12 */
strncpy(TCFbuffer->ApplicationTag, "CCSEND", 63); /* ApplicationTag 59 */
TCFbuffer->RESERVED1 = 0; /* RESERVED1 123 */
TCFbuffer->ConnectSeconds = 0; /* ConnectSeconds 124 */
TCFbuffer->ConnectMinutes = 0; /* ConnectMinutes 125 */
TCFbuffer->ConnectHours = 0; /* ConnectHours 126 */
TCFbuffer->TotalPages = 0; /* TotalPages 127 */
TCFbuffer->PagesSent = 0; /* PagesSent 131 */
TCFbuffer->FilesSent = 0; /* FilesSent 135 */
if((Cover == NULL) && (CoverFile == NULL) && (Logo == NULL)) /* SendCover 137 */
TCFbuffer->SendCover = NO_COVER;
else
TCFbuffer->SendCover = COVER;
TCFbuffer->ErrorCount = 0; /* ErrorCount 138 */
strnset(TCFbuffer->RESERVED2, '\0', 78); /* RESERVED2 140 */
strnset(TCFbuffer->RemoteCSID, '\0', 21); /* RemoteCSID 218 */
strncpy(TCFbuffer->DestinationName, Phone, 31); /* DestinationName 239 */
/* SenderName 271 */
strncpy(TCFbuffer->SenderName, EDBbuffer->DefaultSender, 31);
if(strcmpi(Logo,"default") == 0) { /* LogoFilePath 303 */
strcpy(TCFbuffer->LogoFilePath, EDBbuffer->DefaultDir);
strcat(TCFbuffer->LogoFilePath, EDBbuffer->DefaultLogo);
}
else
if(strlen(Logo) == 0)
strnset(TCFbuffer->LogoFilePath, '\0', 80);
else
if(IsPCXFile(Logo))
strncpy(TCFbuffer->LogoFilePath, Logo, 79);
else
CASError(CASBADLOGOFILE, TRUE, 0);
}
/*---------------------------------------------------------------------------*
* FillFTR() *
*---------------------------------------------------------------------------*
* Fills in an array of FTR structures in preperation for creating a Task *
* Control file. *
*---------------------------------------------------------------------------*
* Parameters: char *filename - Name of file to transfer. *
* FTR *FTRbuffer[] - Array of FTR structures. *
* int num - File number (1-first, 2-second...) *
* Return: none *
*---------------------------------------------------------------------------*/
FillFTR(char *filename, FTR *FTRbuffer[], int num)
{
char *CurrentDir; /* Current working directory. */
/* Lets set the entire buffer to a known state. */
strnset((char *)FTRbuffer[num], '\0', sizeof(FTR));
FTRbuffer[num]->FileType = 0; /* FileType 0 */
if(!FileMode && WideFont)
FTRbuffer[num]->TextSize = 1; /* TextSize 132 col 1 */
else
FTRbuffer[num]->TextSize = 0; /* 80 col */
FTRbuffer[num]->FileStatus = 0; /* FileStatus 2 */
FTRbuffer[num]->BytesSent = 0; /* BytesSent 3 */
FTRbuffer[num]->FileSize = 0; /* FileSize 7 */
FTRbuffer[num]->PagesSent = 0; /* PagesSent 11 */
FTRbuffer[num]->PageCount = 0; /* PageCount 13 */
if(strpbrk(filename, "\\:") == NULL) { /* FileName 15 */
if(getcwd(CurrentDir, 80) == NULL)
CASError(CASBADCWD, TRUE, 0);
else {
strcpy(FTRbuffer[num]->FileName, CurrentDir);
/* Did the current dir end with a backslash? If not, append one. */
if(CurrentDir[strlen(CurrentDir) - 1] != '\\')
strcat(FTRbuffer[num]->FileName, "\\");
strcat(FTRbuffer[num]->FileName, filename);
}
}
else
strcpy(FTRbuffer[num]->FileName, filename);
FTRbuffer[num]->AddPageIncrements = 0; /* AddPageIncrements 95 */
FTRbuffer[num]->PageLength = 0; /* PageLength 96 */
strnset(FTRbuffer[num]->RESERVED, ' ', 31); /* RESERVED 97 */
}
/*---------------------------------------------------------------------------*
* SendMultiple() *
*---------------------------------------------------------------------------*
* Set up an event for CAS. First, write out the TCF and FTR structures to *
* a Task Control file. Next, copy any cover text to it. Once the file is *
* written, it is submitted to CAS with CASSubmitTask(). *
*---------------------------------------------------------------------------*
* Parameters: ECF *TCFbuffer - Filled in ECF structure. *
* FTR *FTRbuffer[] - Filled in FTR structure array. *
* Return: Event Handle of the submitted task. *
*---------------------------------------------------------------------------*/
SendMultiple(ECF *TCFbuffer, FTR *FTRbuffer[])
{
int result, i; /* Function return - Loop counter. */
int CharsUsed = 0; /* Number of chars in cover text. */
int EventHandle; /* Event handle returned from CAS. */
int ErrorCode; /* Error return from CAS functions. */
int spaceleft; /* Keeps track of space on cover page. */
char name[13]; /* Temporary file name. */
FILE *fp; /* DOS handle for temp TCF file. */
FILE *fh; /* DOS handle for cover text file. */
char c[2]; /* Used in reading cover file. */
struct stat fbuffer; /* DOS stat structure. */
char *TCFfile; /* Name of temp file. */
TCFfile = (char *)malloc(62);
if(TCFfile == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Build a temp file name then open the temp file for the TCF & FTR
structure. */
strcpy(name, TEMPLATE);
if(mktemp(name) == NULL)
CASError(CASCREATETEMP, TRUE, 0);
/* Set up the TCF filename. The temp file is placed in the default
directory as specified by the CASGetExternalData function. */
strcpy(TCFfile, EDBbuffer->DefaultDir);
strcat(TCFfile, name);
if((fp = fopen(TCFfile, "wb")) == NULL)
CASError(CASOPENTEMP, TRUE, 0);
/* Write the TCF structures to disk. */
fwrite(TCFbuffer, sizeof(ECF), 1, fp);
/* Copy the cover page text (first from the command line, then from the
specified cover page file 254 */
if(strlen(Cover) != 0) {
CharsUsed = strlen(Cover) + 2;
fwrite(Cover, strlen(Cover), 1, fp);
fwrite("\n\n", 2, 1, fp);
if(strlen(CoverFile) == 0)
fwrite("\0", 1, 1, fp);
}
else
CharsUsed = 0;
if(strlen(CoverFile) != 0) {
/* If cover file was specified, put it in the ECF after the command
line specified cover text. */
if(!IsASCIIFile(CoverFile)) {
fclose(fp);
unlink(TCFfile);
CASError(CASBADCOVERFILE, TRUE, 0);
}
if((fh = fopen(CoverFile, "r")) == NULL)
CASError(CASBADFILEARG, TRUE, 0);
else {
fstat(fileno(fh), &fbuffer);
for (i = ++CharsUsed; (i < TCFbuffer->FTROffset - 383); i++) {
fread(&c[0], 1, 1, fh);
fwrite(&c[0], 1, 1, fp);
}
fclose(fh);
fwrite("\0", 1, 1, fp);
}
}
/* Write the FTR structure(s) to disk. */
for(i = TCFbuffer->FileCount - 1; i >= 0; i--)
fwrite(FTRbuffer[i], sizeof(FTR), 1 ,fp);
fclose(fp);
if((EventHandle = CASSubmitTask(TCFfile)) > 0)
return(EventHandle);
else {
/* Don't forget to clean up temp file on errors! */
unlink(TCFfile);
CASError(CASSEND, TRUE, -EventHandle);
}
}
/*---------------------------------------------------------------------------*
* Is ASCII File? *
*---------------------------------------------------------------------------*
* is_ASCII determines whether the file is ASCII by looking for non_ASCII *
* values, i.e. certain values < 32. If it finds one, the function returns *
* 0. If not, a file handle for the open file is returned. *
*---------------------------------------------------------------------------*
* INPUT : event handle of RCF, file number in FTR chain *
* OUTPUT: returns DOS file handle if file is ASCII, 0 if not *
*---------------------------------------------------------------------------*/
int IsASCIIFile(char *FileName)
{
FILE *fh; /* DOS file handle - file to test. */
unsigned char c; /* Used to read file. */
if((fh = fopen(FileName, "r")) == NULL)
return(FALSE);
while((fread(&c, 1, 1, fh) > 0))
if ((c < 32) && (c != 0x0A) && (c != 0x0C) && (c != 0x0D) &&
(c != 0x1A) && c != 0x09) {
fclose(fh);
return(FALSE); /* File is not ASCII. */
}
fclose(fh);
return(TRUE); /* File is ASCII. */
}
/*---------------------------------------------------------------------------*
* Is .DCX File? *
*---------------------------------------------------------------------------*
* is_DCX checks for the DCX header. If it finds it the function returns *
* the file_handle, otherwise 0. *
*---------------------------------------------------------------------------*
* INPUT : event handle of RCF, file number in FTR chain *
* OUTPUT: returns DOS file handle if file is .DCX, 0 if not *
*---------------------------------------------------------------------------*/
int IsDCXFile(char *FileName)
{
FILE *fh; /* DOS file handle - file to test. */
union {
char buff[4];
long id;
} DCXHeader; /* DCX file signature. */
if((fh = fopen(FileName, "r")) == NULL)
return(FALSE);
fread(&DCXHeader, 4, 1, fh); /* Read four bytes from file. */
fclose(fh);
if(DCXHeader.id == DCXID) /* Check for .DCX header. */
return(TRUE); /* File is .DCX. */
else
return(FALSE); /* File is not .DCX. */
}
/*---------------------------------------------------------------------------*
* Is .PCX File? *
*---------------------------------------------------------------------------*
* is_PCX checks for the PCX header, returning a file handle if the header *
* is there, 0 if not. *
*---------------------------------------------------------------------------*
* INPUT : event handle of RCF, file number in FTR chain *
* OUTPUT: returns DOS file handle if file is .PCX, 0 if not *
*---------------------------------------------------------------------------*/
int IsPCXFile(char *FileName)
{
FILE *fh; /* DOS file handle - file to test. */
char PCXid; /* PCX file signature. */
char Version; /* PCX ... */
char Encode; /* PCX ... */
if((fh = fopen(FileName, "r")) == NULL)
return(FALSE);
fread(&PCXid, 1, 1, fh); /* Read first byte in file. */
fread(&Version, 1, 1, fh); /* Throw away second byte. */
fread(&Encode, 1, 1, fh); /* Read third byte. */
fclose(fh);
if((PCXid == PCXID) && (Encode == PCXENCODE))
return(TRUE); /* File is .PCX. */
else
return(FALSE); /* File is not .PCX. */
}
/*---------------------------------------------------------------------------*
* Main *
*---------------------------------------------------------------------------*
* Submit tasks to CAS for FAX or File Transfer sends. First grab the *
* required buffers, fill in the TCF and FTR structures. If only a single *
* file is specified on the command line, then these structures can be *
* submitted directly to CAS. Otherwise, write the TCF and FTR structures *
* to a disk file (a Task Control File). *
*---------------------------------------------------------------------------*
* Return: The DOS exit code is 0 if no errors are encountered, 1 for *
* commandline syntax errors, 2 for CCAM error, and 3 for DOS *
* errors. *
*---------------------------------------------------------------------------*/
main(int argc, char **argv)
{
int result; /* DOS & CAS function return value. */
int handle; /* Event handle returned from CAS. */
int nfiles; /* Number of files to send. */
char Name[80]; /* File name(s) from command line. */
/* Get command line arguments. On return, the options have been removed
from the command line leaving only the filename(s) and address. */
argc = ParseCommand(argc, argv, SwitchTable, TABLESIZE);
/*If help is wanted, print info and exit (with 0 exit code). */
if(Help || (argc == 1))
CASHelp(DescTable, DESCSIZE, HelpTable, HELPSIZE);
/* At a minimum, one filename must be specified on the command line. */
if(argc < 2)
CASError(CASARGFILE, TRUE, 0);
/* Check to see if the resident scheduler has been installed. */
if((result = CASGetInstalledState()) != INSTALLED)
if(result == NOTiOK)
CASError(CASNOHWO, TRUE, 0);
else
CASError(CASNOHWN, TRUE, 0);
/* Redirect stdout to a file. */
if(RedirOut) {
if((ccout = fopen("OUTPUT.CC", "w")) == NULL)
CASError(CASOPENTEMP, TRUE, 0);
if(-1 == dup2(fileno(ccout), 1))
CASError(CASBADREDIR, TRUE, 0);
}
/* Get buffer for Extended data. */
EDBbuffer = (EDB *)malloc(sizeof(EDB));
if(EDBbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Get External Data Block (ie: path to default logo etc.). */
if(CASGetExternalData(EDBbuffer) != 0)
CASError(CASNOEDB, TRUE, 0);
/* If argc = 2, then only one filename has been specified and we can
use the more efficient send_single command. Otherwise, we need to
build an TCF with multiple FTRs. */
if((argc == 2) && (Logo == NULL)) {
++argv;
strcpy(Name, *argv);
/* Specified files must be of the correct type! ASCII, PCX, or DCX for
Faxes, ASCII, PCX, DCX, or binary for file transfers. */
if(access(Name, 0) == -1)
CASError(CASBADFILEARG, TRUE, 0);
if(!FileMode)
if(!IsPCXFile(*argv) && !IsDCXFile(*argv) && !IsASCIIFile(*argv))
CASError(CASBADFAXFILE, TRUE, 0);
/* Allocate a buffer large enough to hold an SFTR structure. */
SFTRbuffer = (SFTR *)malloc(sizeof(SFTR));
if(SFTRbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Point to filename on commnd line and send it! */
handle = SendSingle(Name, SFTRbuffer);
fprintf(stdout, "Send submitted successfully.\nEvent number is %d\n", handle);
}
else {
/* Number of files to send (argc - 1). */
nfiles = argc - 1;
argv++;
/* Allocate a buffer large enough to hold an TCF structure. */
TCFbuffer = (ECF *)malloc(sizeof(ECF));
if(TCFbuffer == NULL)
CASError(CASNOMEM, TRUE, 0);
FillTCF(TCFbuffer, nfiles);
/* For each file to send, create a File Transfer Record. */
while(argc > 1) {
/* Specified files must be of the correct type! ASCII, PCX, or DCX for
Faxes, ASCII, PCX, DCX, or binary for file transfers. */
strcpy(Name, *argv);
if(access(Name, 0) == -1) {
fprintf(stderr, "%s : ", strupr(Name));
CASError(CASBADFILEARG, TRUE, 0);
}
if(!FileMode)
if(!IsPCXFile(Name) && !IsDCXFile(Name) && !IsASCIIFile(Name))
CASError(CASBADFAXFILE, TRUE, 0);
/* Allocate a buffer large enough to hold an FTR structure. */
FTRbuffer[argc - 2] = (FTR *)malloc(sizeof(FTR));
if(FTRbuffer[argc - 2] == NULL)
CASError(CASNOMEM, TRUE, 0);
/* Fill in the FTR for each file. */
FillFTR(Name, FTRbuffer, (argc - 2));
/* Point to filename on command line, reduce file count. */
++argv; --argc;
}
handle = SendMultiple(TCFbuffer, FTRbuffer);
fprintf(stdout, "Send submitted successfully.\nEvent number is %d\n", handle);
}
exit(0);
}